package ar.com.tallerdos.smartdinner.business;

import java.util.ArrayList;
import java.util.List;

import ar.com.tallerdos.smartdinner.dao.MesaDao;
import ar.com.tallerdos.smartdinner.model.Mesa;
import ar.com.tallerdos.smartdinner.model.Mesa.MesaEstado;

public class MesaBusiness {
    
    private static MesaDao dao;
    
    public static Mesa findById(Integer id) {
	return getDao().findById(id);
    }
    
    public static List<Mesa> findAll() {
	return getDao().findAll();
    }
    
    public static void create(Mesa entity) {
	getDao().create(entity);
    }
    
    public static Boolean delete(Mesa entity) {
	return delete(entity.getId());
    }
    
    public static Boolean delete(Integer id) {
	return getDao().delete(id);
    }
    
    public static Boolean update(Mesa entity) {
	return getDao().update(entity);
    }
    
    public static Boolean createOrUpdate(Mesa entity) {
	return getDao().createOrUpdate(entity);
    }
    
    public static List<Mesa> findMesasAbiertas() {
	List<Mesa> abiertas = new ArrayList<Mesa>();
	for (Mesa mesa : findAll()) {
	    if (MesaEstado.abierta.equals(mesa.getEstado())) {
		abiertas.add(mesa);
	    }
	}
	return abiertas;
    }

    public static MesaDao getDao() {
	if (dao == null) {
	    dao = new MesaDao();
	}
        return dao;
    }

    public static void setDao(MesaDao dao) {
	MesaBusiness.dao = dao;
    }

}
